﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:DA_OVERSEAS
	/// </summary>
	public partial class DA_OVERSEAS : BaseDAL<GSLMS.Entity.TB_DA_OVERSEAS>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public DA_OVERSEAS()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_DA_OVERSEAS model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CORPNAME", model.CORPNAME),
								new OracleParameter("P_REGCAPITAL", model.REGCAPITAL),
								new OracleParameter("P_FOUNDDATE", model.FOUNDDATE),
								new OracleParameter("P_BELONGTO", model.BELONGTO),
								new OracleParameter("P_BUYDATE", model.BUYDATE),
								new OracleParameter("P_SALEDATE", model.SALEDATE),
								new OracleParameter("P_REGADDR", model.REGADDR),
								new OracleParameter("P_TOTALSTOCK", model.TOTALSTOCK),
								new OracleParameter("P_ISSUEDSTOCK", model.ISSUEDSTOCK),
								new OracleParameter("P_DIRECTOR", model.DIRECTOR),
								new OracleParameter("P_SHAREHOLDER", model.SHAREHOLDER),
								new OracleParameter("P_SHAREHOLDERADDR", model.SHAREHOLDERADDR),
								new OracleParameter("P_CORPTYPE", model.CORPTYPE),
								new OracleParameter("P_CORPDETAIL", model.CORPDETAIL),
								new OracleParameter("P_REMARK", model.REMARK)};
  
			for (int i = 0; i < 16; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_da_overseas_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_DA_OVERSEAS model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_CORPNAME", model.CORPNAME),
								new OracleParameter("P_REGCAPITAL", model.REGCAPITAL),
								new OracleParameter("P_FOUNDDATE", model.FOUNDDATE),
								new OracleParameter("P_BELONGTO", model.BELONGTO),
								new OracleParameter("P_BUYDATE", model.BUYDATE),
								new OracleParameter("P_SALEDATE", model.SALEDATE),
								new OracleParameter("P_REGADDR", model.REGADDR),
								new OracleParameter("P_TOTALSTOCK", model.TOTALSTOCK),
								new OracleParameter("P_ISSUEDSTOCK", model.ISSUEDSTOCK),
								new OracleParameter("P_DIRECTOR", model.DIRECTOR),
								new OracleParameter("P_SHAREHOLDER", model.SHAREHOLDER),
								new OracleParameter("P_SHAREHOLDERADDR", model.SHAREHOLDERADDR),
								new OracleParameter("P_CORPTYPE", model.CORPTYPE),
								new OracleParameter("P_CORPDETAIL", model.CORPDETAIL),
								new OracleParameter("P_REMARK", model.REMARK)};
  
			for (int i = 0; i < 16; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_da_overseas_update", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", ID)};
  
				parms[0].Direction = ParameterDirection.Input;

			try
			{
				OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_da_overseas_delete", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_DA_OVERSEAS DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_DA_OVERSEAS model = new GSLMS.Entity.TB_DA_OVERSEAS();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["CORPNAME"]!=null && dr["CORPNAME"].ToString()!="")
				{
					model.CORPNAME=dr["CORPNAME"].ToString();
				}
				if(dr["REGCAPITAL"]!=null && dr["REGCAPITAL"].ToString()!="")
				{
					model.REGCAPITAL=OracleHelper.ToDecimal(dr["REGCAPITAL"].ToString());
				}
				if(dr["FOUNDDATE"]!=null && dr["FOUNDDATE"].ToString()!="")
				{
					model.FOUNDDATE=DateTime.Parse(dr["FOUNDDATE"].ToString());
				}
				if(dr["BELONGTO"]!=null && dr["BELONGTO"].ToString()!="")
				{
                    model.BELONGTO = OracleHelper.ToInt(dr["BELONGTO"].ToString());
				}
				if(dr["BUYDATE"]!=null && dr["BUYDATE"].ToString()!="")
				{
					model.BUYDATE=DateTime.Parse(dr["BUYDATE"].ToString());
				}
				if(dr["SALEDATE"]!=null && dr["SALEDATE"].ToString()!="")
				{
					model.SALEDATE=DateTime.Parse(dr["SALEDATE"].ToString());
				}
				if(dr["REGADDR"]!=null && dr["REGADDR"].ToString()!="")
				{
					model.REGADDR=dr["REGADDR"].ToString();
				}
				if(dr["TOTALSTOCK"]!=null && dr["TOTALSTOCK"].ToString()!="")
				{
					model.TOTALSTOCK=OracleHelper.ToDecimal(dr["TOTALSTOCK"].ToString());
				}
				if(dr["ISSUEDSTOCK"]!=null && dr["ISSUEDSTOCK"].ToString()!="")
				{
					model.ISSUEDSTOCK=OracleHelper.ToDecimal(dr["ISSUEDSTOCK"].ToString());
				}
				if(dr["DIRECTOR"]!=null && dr["DIRECTOR"].ToString()!="")
				{
					model.DIRECTOR=dr["DIRECTOR"].ToString();
				}
				if(dr["SHAREHOLDER"]!=null && dr["SHAREHOLDER"].ToString()!="")
				{
					model.SHAREHOLDER=dr["SHAREHOLDER"].ToString();
				}
				if(dr["SHAREHOLDERADDR"]!=null && dr["SHAREHOLDERADDR"].ToString()!="")
				{
					model.SHAREHOLDERADDR=dr["SHAREHOLDERADDR"].ToString();
				}
				if(dr["CORPTYPE"]!=null && dr["CORPTYPE"].ToString()!="")
				{
					model.CORPTYPE=dr["CORPTYPE"].ToString();
				}
				if(dr["CORPDETAIL"]!=null && dr["CORPDETAIL"].ToString()!="")
				{
					model.CORPDETAIL=dr["CORPDETAIL"].ToString();
				}
				if(dr["REMARK"]!=null && dr["REMARK"].ToString()!="")
				{
					model.REMARK=dr["REMARK"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_DA_OVERSEAS GetByID(long ID)
		{
			GSLMS.Entity.TB_DA_OVERSEAS sModel = new GSLMS.Entity.TB_DA_OVERSEAS();
			string sql = "";
			sql = "select * from TB_DA_OVERSEAS where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_DA_OVERSEAS> GetList(GSLMS.Entity.TB_DA_OVERSEAS searchParam)
		{
			var list=new List<GSLMS.Entity.TB_DA_OVERSEAS>();
			DataTable dt = null;
			string tblName = "TB_DA_OVERSEAS";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_DA_OVERSEAS model = new GSLMS.Entity.TB_DA_OVERSEAS();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

